package com.wyq.group12.controller;

import com.alibaba.fastjson.JSON;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Locale;

/**
 * @ClassName TestController
 * @Description: //TODO Control级别的权限控制
 * @Author wyq
 * @Date 2022/5/10 10:44
 */
@Controller
@RequestMapping("/test")
public class TestController {
    //定义权限
    @Secured("ROLE_TEST1")
    @RequestMapping("/test1")
    public String test1(){
        return "test/test1";
    }

    //定义权限
    @Secured("ROLE_TEST2")
    @RequestMapping("/test2")
    public String test2(){
        return "test/test2";
    }

    /**
     * @Description: //TODO 后台国际化
     * @Author: wyq
     * @Date 2022/5/10 13:03
     */
    @Resource
    private MessageSource messageSource;
    @RequestMapping("/test3")
    @ResponseBody
    public String test3(){
        HashMap<String,Object> message = new HashMap<>();
        Locale locale = LocaleContextHolder.getLocale();
        String msgStr = messageSource.getMessage("test.nav.tip", null, locale);
        message.put("success", true);
        message.put("msg", msgStr);
        message.put("description", msgStr);
        String rst = JSON.toJSONString(message);
        return rst;
    }

}
